<template>
  <d2-container>
    <template slot="header">

      <h2>用户信息管理</h2>
</template>
<template>
      <el-table
        :data="tableData"
        border
        stripe>
        <el-table-column
          fixed
          prop="accountId"
          label="唯一编号"
          width="120">
        </el-table-column>
        <el-table-column
          prop="infoNickname"
          label="用户昵称"
          width="260">
        </el-table-column>
        <el-table-column label="头像" width="100">
          <template slot-scope="scope">
            <el-avatar :size="50" :src="scope.row.infoImg" fit="cover"></el-avatar>
          </template>
        </el-table-column>
        <el-table-column
          prop="infoSex"
          label="用户性别"
          width="130">
        </el-table-column>
        <el-table-column
          prop="infoBirthday"
          label="生日"
          width="200">
        </el-table-column>
        <el-table-column
          label="操作"
          width="100">
          <template slot-scope="scope">
<!--            <el-button size="mini" @click="edit(scope.row)">修改</el-button>-->
            <el-button size="mini" type="danger" @click="deleteBook(scope.row)">删除</el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="infoIntro"
          label="个人介绍">
        </el-table-column>
      </el-table>


      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="pageSize"
        :total="total"
        @current-change="page"
      style="margin-top:25px;">
      </el-pagination>

    </template>
  </d2-container>
</template>

<script>
  import {getUser} from '@/api/user.js';
  import {getUserPage} from '@/api/user.js';
  import {deleteUser} from '@/api/user.js';

  export default {
    name: 'page1',
    methods: {
      edit(row){
        console.log(row)
      },
      deleteBook(row) {
        console.log(row)
        const _this = this
        deleteUser(row.accountId).then(resp => {
          _this.$alert(row.infoNickname + '删除成功', 'ok', {
            confirmButtonText: '确定',
            callback: action => {
              //_this.$router.push('/BookManage')
              window.location.reload()//动态刷新
            }
          });
        })
      },
      page(currentPage) {
        const _this = this;
        getUserPage(currentPage - 1, 4).then(resp => {
          console.log(resp)
          _this.tableData = resp.content
          _this.pageSize = resp.size
          _this.total = resp.totalElements
        })
      }
    },
    data() {
      return {
        test: '1',
        pageSize: 2,
        total: 2,
        tableData: []
      }
    },
    created() {
      const _this = this;
      getUser(0, 4).then(resp => {
        console.log(resp)
        _this.tableData = resp.content
        _this.pageSize = resp.size
        _this.total = resp.totalElements
      })
    }

  }
</script>
